﻿using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Windows.Forms;

namespace AppManage
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
        	AppDomain.CurrentDomain.UnhandledException +=  UnhandledExceptionEventHandler;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
        
        static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                //捕获线程中没有捕获的异常，.net 2.0中如果有未捕获的异常出现会导至进程退出
                //http://support.microsoft.com/?scid=kb;zh-cn;911816&x=11&y=6
                
                using (var fs = new System.IO.FileStream(String.Concat(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,"UnhandledExceptionEventArgs.log"),
                         System.IO.FileMode.Append, System.IO.FileAccess.Write))
                {
                    using (var w = new System.IO.StreamWriter(fs,System.Text.Encoding.UTF8))
                    {
                        w.WriteLine(e.ExceptionObject);
                    }
                }
            }
            catch
            {
            }
        }
    }
}